package controllers;

import models.DriverJourney;
import models.Request;
import models.User;
import play.mvc.With;

import common.FBSecure;

@With(FBSecure.class)
public class Requests extends FBController {

	public static void request(long id) {
		
		setFbIdandName();

		User user = getUser();
		
		DriverJourney driverJourney = DriverJourney.findById(id);
		
		user.addRequest(driverJourney.getUser(), user, driverJourney);
		
		renderTemplate("DriverJourneyDetails/driverjourneydetails.html", user, driverJourney);
	}
	
	public static void comingrequests() {
		
		setFbIdandName();

		User user = getUser();
		
		render(user);
	}
	
	public static void sentrequests() {
		
		setFbIdandName();

		User user = getUser();
		
		render(user);
	}
	
	public static void acceptrequest(long id) {
		
		setFbIdandName();

		User user = getUser();
		
		Request request = Request.findById(id);
		DriverJourney journey = request.getJourney();
		
		user.acceptRequest(request, journey);
		
		
		renderTemplate("Requests/comingrequests.html", user);
	}
	
	public static void rejectrequest(long id) {
		
		setFbIdandName();

		User user = getUser();
		
		Request request = Request.findById(id);
		DriverJourney journey = request.getJourney();
		
		user.rejectRequest(request, journey);
		
		renderTemplate("Requests/comingrequests.html", user);
	}
	
}
